﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel;

namespace devtm.Configuration.TypeConverters
{

    public class MyTypeConverter : TypeConverter
    {


        public override bool CanConvertFrom(ITypeDescriptorContext context, Type sourceType)
        {
            return base.CanConvertFrom(context, sourceType);
        }


        public override bool CanConvertTo(ITypeDescriptorContext context, Type destinationType)
        {
            return base.CanConvertTo(context, destinationType);
        }


        public override object ConvertFrom(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value)
        {

            if (value is string)
                return Type.GetType((string)value);
            else
                if (value is Type)
                    return (value as Type).AssemblyQualifiedName;

            return base.ConvertFrom(context, culture, value);

        }


        public override object ConvertTo(ITypeDescriptorContext context, System.Globalization.CultureInfo culture, object value, Type destinationType)
        {

            if (destinationType == typeof(string))
                return (value as Type).AssemblyQualifiedName;
            else
                if (destinationType == typeof(Type))
                    return Type.GetType((string)value);


            return base.ConvertTo(context, culture, value, destinationType);

        }

    }


}
